<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="付费者ID" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="付费者ID"></el-input>
    </el-form-item>
    <el-form-item label="推荐者ID" prop="recommId">
      <el-input v-model="dataForm.recommId" placeholder="推荐者ID"></el-input>
    </el-form-item>
    <el-form-item label="订单编号" prop="orderNo">
      <el-input v-model="dataForm.orderNo" placeholder="订单编号"></el-input>
    </el-form-item>
    <el-form-item label="返佣类型1:福利订单返佣 2:分享赚 3:推广金额 4:联盟店线上订单佣金 5:区域线下买单佣金 6:新用户首单奖励 7推广充值返现 8推广订单交易返现 9后台佣金调整 10:采购订单返佣" prop="commissionType">
      <el-input v-model="dataForm.commissionType" placeholder="返佣类型1:福利订单返佣 2:分享赚 3:推广金额 4:联盟店线上订单佣金 5:区域线下买单佣金 6:新用户首单奖励 7推广充值返现 8推广订单交易返现 9后台佣金调整 10:采购订单返佣"></el-input>
    </el-form-item>
    <el-form-item label="佣金获得金额" prop="commissionMoney">
      <el-input v-model="dataForm.commissionMoney" placeholder="佣金获得金额"></el-input>
    </el-form-item>
    <el-form-item label="获得购买者用户的佣金百分比" prop="commissionPercent">
      <el-input v-model="dataForm.commissionPercent" placeholder="获得购买者用户的佣金百分比"></el-input>
    </el-form-item>
    <el-form-item label="佣金消息备注（福利商品零售利润,推广费用）" prop="commissionMessage">
      <el-input v-model="dataForm.commissionMessage" placeholder="佣金消息备注（福利商品零售利润,推广费用）"></el-input>
    </el-form-item>
    <el-form-item label="推荐者用户类型" prop="recommUserType">
      <el-input v-model="dataForm.recommUserType" placeholder="推荐者用户类型"></el-input>
    </el-form-item>
    <el-form-item label="商品总利润" prop="goodsProfits">
      <el-input v-model="dataForm.goodsProfits" placeholder="商品总利润"></el-input>
    </el-form-item>
    <el-form-item label="商品零售价格" prop="goodsPrice">
      <el-input v-model="dataForm.goodsPrice" placeholder="商品零售价格"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="佣金状态 0:删除 1:正常" prop="state">
      <el-input v-model="dataForm.state" placeholder="佣金状态 0:删除 1:正常"></el-input>
    </el-form-item>
    <el-form-item label="是否在APP展示：1展示 0不展示" prop="appExhibition">
      <el-input v-model="dataForm.appExhibition" placeholder="是否在APP展示：1展示 0不展示"></el-input>
    </el-form-item>
    <el-form-item label="是否提现：0未提现 1已提现 2提现中 " prop="isWithdrawa">
      <el-input v-model="dataForm.isWithdrawa" placeholder="是否提现：0未提现 1已提现 2提现中 "></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          commissionId: 0,
          userId: '',
          recommId: '',
          orderNo: '',
          commissionType: '',
          commissionMoney: '',
          commissionPercent: '',
          commissionMessage: '',
          recommUserType: '',
          goodsProfits: '',
          goodsPrice: '',
          createTime: '',
          state: '',
          appExhibition: '',
          isWithdrawa: ''
        },
        dataRule: {
          userId: [
            { required: true, message: '付费者ID不能为空', trigger: 'blur' }
          ],
          recommId: [
            { required: true, message: '推荐者ID不能为空', trigger: 'blur' }
          ],
          orderNo: [
            { required: true, message: '订单编号不能为空', trigger: 'blur' }
          ],
          commissionType: [
            { required: true, message: '返佣类型1:福利订单返佣 2:分享赚 3:推广金额 4:联盟店线上订单佣金 5:区域线下买单佣金 6:新用户首单奖励 7推广充值返现 8推广订单交易返现 9后台佣金调整 10:采购订单返佣不能为空', trigger: 'blur' }
          ],
          commissionMoney: [
            { required: true, message: '佣金获得金额不能为空', trigger: 'blur' }
          ],
          commissionPercent: [
            { required: true, message: '获得购买者用户的佣金百分比不能为空', trigger: 'blur' }
          ],
          commissionMessage: [
            { required: true, message: '佣金消息备注（福利商品零售利润,推广费用）不能为空', trigger: 'blur' }
          ],
          recommUserType: [
            { required: true, message: '推荐者用户类型不能为空', trigger: 'blur' }
          ],
          goodsProfits: [
            { required: true, message: '商品总利润不能为空', trigger: 'blur' }
          ],
          goodsPrice: [
            { required: true, message: '商品零售价格不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          state: [
            { required: true, message: '佣金状态 0:删除 1:正常不能为空', trigger: 'blur' }
          ],
          appExhibition: [
            { required: true, message: '是否在APP展示：1展示 0不展示不能为空', trigger: 'blur' }
          ],
          isWithdrawa: [
            { required: true, message: '是否提现：0未提现 1已提现 2提现中 不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.commissionId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.commissionId) {
            this.$http({
              url: this.$http.adornUrl(`/commission/shoppingcommission/info/${this.dataForm.commissionId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userId = data.shoppingcommission.userId
                this.dataForm.recommId = data.shoppingcommission.recommId
                this.dataForm.orderNo = data.shoppingcommission.orderNo
                this.dataForm.commissionType = data.shoppingcommission.commissionType
                this.dataForm.commissionMoney = data.shoppingcommission.commissionMoney
                this.dataForm.commissionPercent = data.shoppingcommission.commissionPercent
                this.dataForm.commissionMessage = data.shoppingcommission.commissionMessage
                this.dataForm.recommUserType = data.shoppingcommission.recommUserType
                this.dataForm.goodsProfits = data.shoppingcommission.goodsProfits
                this.dataForm.goodsPrice = data.shoppingcommission.goodsPrice
                this.dataForm.createTime = data.shoppingcommission.createTime
                this.dataForm.state = data.shoppingcommission.state
                this.dataForm.appExhibition = data.shoppingcommission.appExhibition
                this.dataForm.isWithdrawa = data.shoppingcommission.isWithdrawa
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/commission/shoppingcommission/${!this.dataForm.commissionId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'commissionId': this.dataForm.commissionId || undefined,
                'userId': this.dataForm.userId,
                'recommId': this.dataForm.recommId,
                'orderNo': this.dataForm.orderNo,
                'commissionType': this.dataForm.commissionType,
                'commissionMoney': this.dataForm.commissionMoney,
                'commissionPercent': this.dataForm.commissionPercent,
                'commissionMessage': this.dataForm.commissionMessage,
                'recommUserType': this.dataForm.recommUserType,
                'goodsProfits': this.dataForm.goodsProfits,
                'goodsPrice': this.dataForm.goodsPrice,
                'createTime': this.dataForm.createTime,
                'state': this.dataForm.state,
                'appExhibition': this.dataForm.appExhibition,
                'isWithdrawa': this.dataForm.isWithdrawa
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
